﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma  once
#include "GmUiCommonComponent.h"
#include <QFrame>
#include <unordered_map>


class QPushButton;
class QLabel;

class  GM_UI_COMMON_COMPONENT_EXPORT GmTitleBar : public QFrame
{
    Q_OBJECT

public:
    explicit GmTitleBar(QWidget* parent = 0,std::wstring objectNamePrefix=L"");

    enum class EButtonType : std::uint8_t {
        Minimize,
        Maximize,
        Restore,
        Close
    };


    void setIconVisible(bool visible);
    void setText(const QString& text);
    void setTextVisible(bool visible);
    void setMinButtonVisible(bool visible);
    void setMaxButtonVisible(bool visible);
    void setRestoreButtonVisible(bool visible);
    void setCloseButtonVisible(bool visible);

    void addWidget(QWidget* widget, int stretch = 0, Qt::Alignment alignment = 0,
                   bool at_end = true);
    void removeWidget(QWidget* widget);

    void replaceIcons(const std::unordered_map< EButtonType, std::wstring > & iconPathes);
    void replaceIcon(const EButtonType, const std::wstring & iconPath);

signals:
    void minimizeRequested();
    void normalRequested();
    void maximizeRequested();
    void closeRequested();
    void moveRequested(const QPoint& cursorPos, const QPoint& offset);

protected:
    void mousePressEvent(QMouseEvent* e) Q_DECL_OVERRIDE;
    void mouseMoveEvent(QMouseEvent* e) Q_DECL_OVERRIDE;
    void mouseReleaseEvent(QMouseEvent* e) Q_DECL_OVERRIDE;
    bool event(QEvent* e) Q_DECL_OVERRIDE;

private:
    QLabel* m_pIconLabel;
    QLabel* m_pTextLabel;
    QPushButton* m_pMinButton;
    QPushButton* m_pMaxButton;
    QPushButton* m_pRestoreButton;
    QPushButton* m_pCloseButton;
    bool m_bPressed;
    QPoint m_pressPos;
    QPoint m_moveStartPos;
};


